/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package cn.edu.ntu.yyl.controller.admin;

import cn.edu.ntu.yyl.service.ArticleService;
import cn.edu.ntu.yyl.service.ArticleShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

import static cn.edu.ntu.yyl.tool.LayuiTool.objectToJSON;
@RestController
public class AdminConsole {
    @Autowired
    ArticleService articleService;
    @Autowired
    ArticleShowService articleShowService;
    //新管理员面板
    @RequestMapping({"/getarticlelist"})
    public Object DashboardIndex(HttpServletRequest request){
        //获取参数
        String status = request.getParameter("date");
        Integer date=0;
        if (status!=null){date = Integer.valueOf(status);}
        switch (date) {
            case 2:
            {
                List<Object> yesterdayArticle = Arrays.asList(articleShowService.Show(articleService.SelectYesterdayArticle()).toArray());
                return objectToJSON(yesterdayArticle);
            }
            case 7: {
                List<Object> sevenDayArticle = Arrays.asList(articleShowService.Show(articleService.SelectSevenDayArticle()).toArray());
                return objectToJSON(sevenDayArticle);
            }
            case 14: {
                List<Object> fourteenDayArticle =  Arrays.asList(articleShowService.Show(articleService.SelectFourteenDayArticle()).toArray());
                return objectToJSON(fourteenDayArticle);
            }
            case 30: {
                List<Object> monthArticle  = Arrays.asList(articleShowService.Show(articleService.SelectMonthArticle()).toArray());
                return objectToJSON(monthArticle);
            }
            case 0:{
                List<Object> allArticle = Arrays.asList(articleShowService.Show(articleService.SelectAllArticle()).toArray());
                return objectToJSON(allArticle);
            }
            case 1:
            default: {
                List<Object> todayArticle = Arrays.asList(articleShowService.Show(articleService.SelectTodayArticle()).toArray());
                return objectToJSON(todayArticle);
            }

        }
    }
}
